<?php

/**
 * common actions.
 *
 * @package    tsantek-shop
 * @subpackage common
 * @author     Tomislav Šantek
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class commonActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
      $maxPerPage = sfconfig::get('app_Frontpage_maxPerPage', 12);
      $page = $request->getParameter('page', 1);

      $this->pager = new sfDoctrinePager('Product', $maxPerPage);
      $this->pager->setQuery(ProductTable::getByFeaturedQuery());
      $this->pager->setPage($page);

      if($this->pager->getLastPage() > $page)
        $this->redirect ($this->generateUrl ('homepage', array('page'=>1)));

      $this->pager->init();

    //$this->forward('default', 'module');
  }

    public function executeAutocompletecity(sfWebRequest $request)
    {
        $result = Doctrine_Core::getTable('City')->findCityByName($request['q']);//->toKeyValueArray('id', 'naziv_pu');
        $output = array();
        foreach($result as $r)
            $output[$r->getId()] = $r->getNazivPu().' ('.$r->getBrojPu().')';
        return $this->renderText(json_encode($output));
    }
}
